<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['status']){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('pinglog',$parameter,$total);
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['tomember']=cfc('core')->member_show($item['tomid']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'记录管理'),
		),
		'list'=>array('data'=>'list','tip'=>'发送约会瓶，异性看到感兴趣，才可以选择是否发起《约红娘》！','edit'=>false,'list'=>array(
			array('name'=>'member','title'=>'发送人','type'=>'member'),
			array('name'=>'tomember','title'=>'接收人','type'=>'member'),
			array('name'=>'desc','title'=>'内容','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'pinglog_status'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		),'action'=>array(
			array('type'=>'href','op'=>'look','title'=>'查看'),
		)),
		'search'=>array(
			array('type'=>'radio','width'=>15,'name'=>'status','title'=>'状态','options'=>'pinglog_status'),
			array('type'=>'choose','width'=>18,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
		),
	);
	$return['htmls']=$htmls;
	$return['pinglog_status']=$this->pinglog_status;
	exi($return);
}
if($_RQ['op']=='look'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_ailiao_pinglog',array('id'=>$id));
	}else{
		$item=array();
	}
	$item['member']=cfc('core')->member_show($item['mid']);
	$item['tomember']=cfc('core')->member_show($item['tomid']);
	$item['images']=json_decode($item['images'],true);
    $return['item']=$item;	
	$htmls=array( 
		'type'=>'look',
		'desc'=>'记录查看',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回记录列表'),
		),
		'look'=>array(
			array('name'=>'member','title'=>'发送人','type'=>'member'),
			array('name'=>'tomember','title'=>'接收人','type'=>'member'),
			array('name'=>'images','title'=>'朋友圈图片','type'=>'images'),
			array('name'=>'desc','title'=>'内容','type'=>'richtext'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		)
	);
	$return['pinglog_status']=$this->pinglog_status;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		$this->delete('pinglog',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				$this->delete('pinglog',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
?>